/**
 * Boton HR para el htmleditor
 * @autor joshua
 * @fecha 20 de marzo de 2012
 **/
Ext.ns('Extmx.ux.htmleditor.Editor');

Extmx.ux.htmleditor.Editor = Ext.extend(Ext.form.HtmlEditor, {
    plugins: [new Extmx.ux.htmleditor.Quote(), new Extmx.ux.htmleditor.InsertMultimedia()],
  /*  adjustFont: function (btn,evento,tamano){ tamano=18;
        if(Ext.isEmpty(tamano)){
        //si no se recibio el tamano
            Extmx.ux.htmleditor.Editor.superclass.adjustFont.call(this,btn,evento);
        }else{

            /*var adjust = btn.getItemId() == 'increasefontsize' ? 1 : -1,
            doc = this.getDoc(),
            v = parseInt(doc.queryCommandValue('FontSize') || 2, 10);* /

            if((Ext.isSafari && !Ext.isSafari2) || Ext.isChrome || Ext.isAir){
                // Safari 3 values
                // 1 = 10px, 2 = 13px, 3 = 16px, 4 = 18px, 5 = 24px, 6 = 32px
                /*if(v <= 10){
                    v = 1 + adjust;
                }else if(v <= 13){
                    v = 2 + adjust;
                }else if(v <= 16){
                    v = 3 + adjust;
                }else if(v <= 18){
                    v = 4 + adjust;
                }else if(v <= 24){
                    v = 5 + adjust;
                }else {
                    v = 6 + adjust;
                }* /
                v = 4;//v.constrain(1, 6);
            }else{
                if(Ext.isSafari){ // safari
                    adjust =18;//*= 2;
                }
                v = 22/*Math.max(1, v+adjust)* / //+ (Ext.isSafari ? 'px' : 0);
            }
            alert(v);
            this.execCmd('FontSize', v);
        }
    },
*/
    getDocMarkup : function(){
            var markup = '<html><head><style type="text/css">body{border:0;margin:0;padding:3px;height:98%;cursor:text;font-size: 13px;}</style>';
            //if(this.styles) {
                  //for (var i=0;i<this.styles.length;i++) {
                  markup = markup + '<link rel="stylesheet" type="text/css" href="../../css/web/blockquote.css" />';//'+this.styles[i]+' />';
                  //}
            //}
            markup = markup + '</head><body></body></html>';
            return markup;
    },


    //-----------------
    initEditor : function(){
        //Destroying the component during/before initEditor can cause issues.
        try{
            var dbody = this.getEditorBody(),
                ss = this.el.getStyles( 'font-family', 'background-image', 'background-repeat', 'background-color', 'color'),//'font-size',
                doc,
                fn;

            ss['background-attachment'] = 'fixed'; // w3c
            dbody.bgProperties = 'fixed'; // ie

            Ext.DomHelper.applyStyles(dbody, ss);

            doc = this.getDoc();

            if(doc){
                try{
                    Ext.EventManager.removeAll(doc);
                }catch(e){}
            }

            /*
             * We need to use createDelegate here, because when using buffer, the delayed task is added
             * as a property to the function. When the listener is removed, the task is deleted from the function.
             * Since onEditorEvent is shared on the prototype, if we have multiple html editors, the first time one of the editors
             * is destroyed, it causes the fn to be deleted from the prototype, which causes errors. Essentially, we're just anonymizing the function.
             */
            fn = this.onEditorEvent.createDelegate(this);
            Ext.EventManager.on(doc, {
                mousedown: fn,
                dblclick: fn,
                click: fn,
                keyup: fn,
                buffer:100
            });

            if(Ext.isGecko){
                Ext.EventManager.on(doc, 'keypress', this.applyCommand, this);
            }
            if(Ext.isIE || Ext.isWebKit || Ext.isOpera){
                Ext.EventManager.on(doc, 'keydown', this.fixKeys, this);
            }
            doc.editorInitialized = true;
            this.initialized = true;
            this.pushValue();
            this.setReadOnly(this.readOnly);
            this.fireEvent('initialize', this);
        }catch(e){}
    }

});